﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：李刚
    //
    // 文件名：RegisterGoods.aspx.cs
    // 文件功能描述：医疗机构自行添加产品
    // 创建标识：李刚 2009-07-17
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Collections.Generic;

namespace HZ.DrugTrade.Web.Admin.BidProdManage
{
    public partial class RegisterGoods : BasePage
    {

        public RegisterGoods()
        {
            this.ModuleNo = Module.产品库管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //绑定下拉框
                BindSortList();
                BindLevelList();
            }
        }

        /// <summary>
        /// 绑定产品分类下拉框
        /// </summary>
        private void BindSortList()
        {
            IBLL_Sort ibbs = Factory.IBLL_Sort();
            IList<Sort> Lsort = ibbs.GetAllSort(null);

            this.dplSort.DataTextField = "SortName";
            this.dplSort.DataValueField = "SortID";
            this.dplSort.DataSource = Lsort;
            this.dplSort.DataBind();

            ListItem item = new ListItem();
            item.Text = "==请选择产品分类==";
            item.Value = Constants.ALL_ITEM_VALUE;
            dplSort.Items.Insert(0, item);
        }
        /// <summary>
        /// 绑定质量层次下拉框
        /// </summary>
        private void BindLevelList()
        {
            int totalRecord;
            BLL.BLL_Common commonCtr = new HZ.DrugTrade.BLL.BLL_Common();
            DataTable table = commonCtr.GetAllQualityLevel(1, 0, out totalRecord);

            this.dplLevel.DataTextField = "LevellName";
            this.dplLevel.DataValueField = "LevelID";
            this.dplLevel.DataSource = table;
            this.dplLevel.DataBind();

            ListItem item = new ListItem();
            item.Text = "==请选择质量层次==";
            item.Value = Constants.ALL_ITEM_VALUE;
            dplLevel.Items.Insert(0, item);
 
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtGoodsName.Text.Trim()) || string.IsNullOrEmpty(txtMaterial.Text.Trim())
                || string.IsNullOrEmpty(txtOutlookc.Text.Trim()) || string.IsNullOrEmpty(txtCompanyName.Text.Trim()) || string.IsNullOrEmpty(txtLimitPrice.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("请填写必填项！", this);
                return;
            }

            CustomGoods model = new CustomGoods();
            model.HospitalID = ""; //
            model.HospitalName = CurrentAccount.GetUser().Org.OrgName;
            model.GoodsName = txtGoodsName.Text.Trim();
            model.Material = txtMaterial.Text.Trim();
            model.Outlookc = txtOutlookc.Text.Trim();
            model.Unit = txtUnit.Text.Trim();
            model.CompanyName = txtCompanyName.Text.Trim();
            model.SortID = dplSort.SelectedValue;
            model.QualityLevel = dplLevel.SelectedValue;
            model.LimitPrice = string.IsNullOrEmpty(txtLimitPrice.Text.Trim()) ? 0 : new HZ.Common.ConvertHelper(txtLimitPrice.Text.Trim()).ToDecimal; 
            model.Note = txtNote.Text.Trim();

            IBLL_CustomGoods cstCtrl = Factory.BLL_CustomGoods();
            int result = cstCtrl.AddCustomGoods(model);
            if (result == 1)
            {
                PageInfo("新产品申报成功！请等待审核。", "CustomGoodsCheckList.aspx");
            }
            else
            {
                PageError("新产品添加失败，已有重复产品。","");
            }

        }
    }
}
